package com.cn.sc.scitc.cyol;


import org.json.JSONException;
import org.json.JSONObject;

import java.io.*;
import java.net.URL;
import java.net.HttpURLConnection;
import org.json.JSONArray;
import org.json.JSONObject;


public class TryLogin {
    private String String_Login_Json;
    private String Object_Login_token;

    public TryLogin() {
        JSONObject jsonParam = new JSONObject();
        jsonParam.put("password", "输入你的密码");
        jsonParam.put("username", "输入你的账户");
        String urls ="http://dxx.scyol.com/backend/adminUser/login";

        GetJson getJson = new GetJson();
        String_Login_Json = getJson.GetJson(urls,jsonParam);
        init_token();
    }


    private void init_token(){
        int index = String_Login_Json.indexOf("token") + 8;
        int end=0;
        if(index == -1){
            String_Login_Json = null;
        }else{
            for (int i=index;i<String_Login_Json.length();i++){
                if(String_Login_Json.charAt(i) == '"'){
                    System.out.println(String_Login_Json.charAt(i));
                    end = i;
                    break;
                }
            }
            Object_Login_token = String_Login_Json.substring(index,end);
//            System.out.println("字符串遍历token：" + Object_Login_token);
        }
    }

    public String Get_String_Login_Json(){
        return String_Login_Json;
    }

    public String GetObject_Login_token(){
        return Object_Login_token;
    }
}
